/*
 * Created on Feb 25, 2005
 */
package com.scalar.chiptrack.finance.openpo.forms;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.finance.openpo.*;
import com.scalar.chiptrack.commons.Address;
import com.scalar.chiptrack.commons.ClientInfo;
import com.scalar.chiptrack.utils.ConfigManager;
import com.scalar.chiptrack.utils.PDFGenerator;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.ScalarException;

import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.text.DecimalFormat;

/**
 * @author Ravikanth
**/
public class PurchaseOrderReceiptForm extends ActionForm 
{
	private int receipt_id = -1;
	private String receipt_Number= null;
	private int purchaseOrder_Id = -1;
	private String purchaseOrderNumber = null;
	private String vendorName = null;
	private int vendor_id = -1;
	private String receiptDate = null;
	private String status = null;
	
	private String last_modified_on = null;
	private String last_modified_by	= null;
	
	private double sub_total = 0.0;
	private double trade_Discount = 0.0;
	private double frieght = 0.0;
	private double miscellaneous = 0.0;
	private double tax = 0.0;
	private double total = 0.0;
    private String batchSource = null;
    private String batchNumber = null;
    private String vendorDocNumber = null;
    private ClientInfo clientInfo = null;

	private ReceivingLineItemList receivingLineItemList;

    private String poTaxType = null;
    private String newPoState = null;
    private String newPoTax = null;
    private int poType;
    private PurchaseOrderLineItemLotDataEntryList openPOLotList;
    private String invoiceNumber = null;
    private double poMaxAmt;
    private double prevReceiptsTotal;

    public String getPoTaxType() {
        return poTaxType;
    }

    public void setPoTaxType(String poTaxType) {
        this.poTaxType = poTaxType;
    }

    public String getNewPoState() {
        return newPoState;
    }

    public void setNewPoState(String newPoState) {
        this.newPoState = newPoState;
    }

    public String getNewPoTax() {
        return newPoTax;
    }

    public void setNewPoTax(String newPoTax) {
        this.newPoTax = newPoTax;
    }

	/**
	 * For resetting the PurchaseOrderForm Values
	 * @param mapping
	 * @param request
	 */
	public void reset( ActionMapping mapping, HttpServletRequest request )
	{
		ReceivingLineItem receivingLineItem = null;
		ReceivingLineItemList receivingLineItemListTemp = new ReceivingLineItemList();
		
		if( receivingLineItemList != null )
		{
			for( int i=0; i < receivingLineItemList.size(); i++ )
			{
				receivingLineItem = ( ReceivingLineItem )receivingLineItemList.get( i );
				receivingLineItem.setSelected( false );
                /*PurchaseOrderLineItemLotDataEntryList purchaseOrderLineItemLotDataEntryList = receivingLineItem.getPurchaseOrderLineItemLotDataEntryList();
                if ( purchaseOrderLineItemLotDataEntryList != null )
                {
                    for ( int j=0; j < purchaseOrderLineItemLotDataEntryList.size(); j++ )
                    {
                        PurchaseOrderLineItemLotDataEntry purchaseOrderLineItemLotDataEntry = (PurchaseOrderLineItemLotDataEntry)purchaseOrderLineItemLotDataEntryList.get( j );
                        purchaseOrderLineItemLotDataEntry.setSelected( false );
                    }
                }*/
                receivingLineItemListTemp.add(receivingLineItem);
			}
		}
		this.setReceivingLineItemList( receivingLineItemListTemp );
	} 
	
	
	/**
	 * @return
	 */
	public double getFrieght()
	{
		return frieght;
	}

	/**
	 * @return
	 */
	public String getLast_modified_by()
	{
		return last_modified_by;
	}

	/**
	 * @return
	 */
	public String getLast_modified_on()
	{
		return last_modified_on;
	}

	/**
	 * @return
	 */
	public double getMiscellaneous()
	{
		return miscellaneous;
	}

	/**
	 * @return
	 */
	public int getPurchaseOrder_Id()
	{
		return purchaseOrder_Id;
	}

	/**
	 * @return
	 */
	public String getPurchaseOrderNumber()
	{
		return purchaseOrderNumber;
	}

	/**
	 * @return
	 */
	public int getReceipt_id()
	{
		return receipt_id;
	}

	/**
	 * @return
	 */
	public String getReceipt_Number()
	{
		return receipt_Number;
	}

	/**
	 * @return
	 */
	public String getReceiptDate()
	{
		return receiptDate;
	}

	/**
	 * @return
	 */
	public ReceivingLineItemList getReceivingLineItemList()
	{
		return receivingLineItemList;
	}

	/**
	 * @return
	 */
	public String getStatus()
	{
		return status;
	}

	/**
	 * @return
	 */
	public double getSub_total()
	{
		return sub_total;
	}

    public String getSub_totalAsString()
    {
        DecimalFormat formatter = new DecimalFormat("0.00");
        String output = formatter.format( sub_total);
        return output;
    }


	/**
	 * @return
	 */
	public double getTax()
	{
		return tax;
	}

    /**
     *
     * @return tax as string
     */
    public String getTaxAsString()
    {
        DecimalFormat formatter = new DecimalFormat("0.00");
        String output = formatter.format( tax);
        return output;
    }


	/**
	 * @return
	 */
	public double getTrade_Discount()
	{
		return trade_Discount;
	}

	/**
	 * @return
	 */
	public int getVendor_id()
	{
		return vendor_id;
	}

	/**
	 * @return
	 */
	public String getVendorName()
	{
		return vendorName;
	}

	/**
	 * @param d
	 */
	public void setFrieght(double d)
	{
		frieght = d;
	}

	/**
	 * @param string
	 */
	public void setLast_modified_by(String string)
	{
		last_modified_by = string;
	}

	/**
	 * @param string
	 */
	public void setLast_modified_on(String string)
	{
		last_modified_on = string;
	}

	/**
	 * @param d
	 */
	public void setMiscellaneous(double d)
	{
		miscellaneous = d;
	}

	/**
	 * @param i
	 */
	public void setPurchaseOrder_Id(int i)
	{
		purchaseOrder_Id = i;
	}

	/**
	 * @param string
	 */
	public void setPurchaseOrderNumber(String string)
	{
		purchaseOrderNumber = string;
	}

	/**
	 * @param i
	 */
	public void setReceipt_id(int i)
	{
		receipt_id = i;
	}

	/**
	 * @param string
	 */
	public void setReceipt_Number(String string)
	{
		receipt_Number = string;
	}

	/**
	 * @param string
	 */
	public void setReceiptDate(String string)
	{
		receiptDate = string;
	}

	/**
	 * @param list
	 */
	public void setReceivingLineItemList(ReceivingLineItemList list)
	{
		receivingLineItemList = list;
	}

	/**
	 * @param string
	 */
	public void setStatus(String string)
	{
		status = string;
	}

	/**
	 * @param d
	 */
	public void setSub_total(double d)
	{
		sub_total = d;
	}

	/**
	 * @param d
	 */
	public void setTax(double d)
	{
		tax = d;
	}

	/**
	 * @param d
	 */
	public void setTrade_Discount(double d)
	{
		trade_Discount = d;
	}

	/**
	 * @param i
	 */
	public void setVendor_id(int i)
	{
		vendor_id = i;
	}

	/**
	 * @param string
	 */
	public void setVendorName(String string)
	{
		vendorName = string;
	}

	/**
	 * @return
	 */
	public double getTotal()
	{
		return total;
	}

    public String getTotalAsString()
    {
        DecimalFormat formatter = new DecimalFormat("0.00");
        String output = formatter.format( total);
        return output;
    }



	/**
	 * @param d
	 */
	public void setTotal(double d)
	{
		total = d;
	}
    public ClientInfo getClientInfo() {
        return clientInfo;
    }

    public void setClientInfo(ClientInfo clientInfo) {
        this.clientInfo = clientInfo;
    }

    public String getBatchSource()
    {
        return batchSource;
    }

    public void setBatchSource( String batchSource )
    {
        this.batchSource = batchSource;
    }

    public String getBatchNumber()
    {
        return batchNumber;
    }

    public void setBatchNumber( String batchNumber )
    {
        this.batchNumber = batchNumber;
    }

    public String getVendorDocNumber()
    {
        return vendorDocNumber;
    }

    public void setVendorDocNumber( String vendorDocNumber )
    {
        this.vendorDocNumber = vendorDocNumber;
    }


    public int getPoType() {
        return poType;
    }

    public void setPoType(int poType) {
        this.poType = poType;
    }

    public String getClientAddrWithOutEmailObjFormatted()
	{
        Address add = clientInfo.getAddress();
        StringBuffer formatAddress = new StringBuffer();

        formatAddress.append ( ( ( clientInfo.getClientName() == null ) || ( ( clientInfo.getClientName().trim().length() == 0 ) ) ) ? "" :"<BR>" +  clientInfo.getClientName() );

        formatAddress.append ( ( ( add.getAddress1() == null ) || ( ( add.getAddress1().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getAddress1() );
        formatAddress.append ( ( ( add.getAddress2() == null ) || ( ( add.getAddress2().trim().length() == 0 ) ) ) ? "" :"<BR>" + add.getAddress2() );
        formatAddress.append ( ( ( add.getAddress3() == null ) || ( ( add.getAddress3().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress3() );
        formatAddress.append ( ( ( add.getAddress4() == null ) || ( ( add.getAddress4().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress4() );

        String formatState = PurchaseOrderReceiptForm.getFormatedCityState(add);
        if ( formatState.trim().length() !=0 )
           formatAddress.append ("<BR>"+formatState);
        formatAddress.append ( ( ( add.getPhoneNumber() != null ) && ( add.getPhoneNumber().trim().length() > 0 ) ) ?  "<BR>Tel: "+ add.getPhoneNumber() : "" );
        formatAddress.append ( ( ( add.getFaxNumber() != null ) && ( add.getFaxNumber().trim().length() > 0 ) ) ?  "<BR>Fax: "+ add.getFaxNumber() : "" );

        return formatAddress.toString() ;
	}
     public static String getFormatedCityState( Address add )
	{
	    String addr = "";
        if( add.getCity() != null && add.getCity() .trim() .length() != 0 )
            addr = add.getCity() + ",&nbsp;" ;
        if (  add.getState() != null  &&  add.getState().trim().length() != 0 )
		    addr =  addr  + add.getState();
		if( add.getZipCode() != null &&  add.getZipCode().trim().length() != 0 )
		{
		     if ( addr.trim().length() !=0 )
		         addr = addr + "&nbsp;-&nbsp;" + add.getZipCode();
		    else
				 addr = addr + add.getZipCode();
		}
		if( add.getCountry() != null && add.getCountry().trim().length() != 0 )
	    {
	        if ( addr.trim().length() != 0 )
			    addr = addr + ",&nbsp;" + add.getCountry();
			else
			    addr = addr + add.getCountry();
	   	}

		return addr;
	}

    public String  getPurchaseOrderAckHtmlFile( String host, PurchaseOrderReceiptForm purchaseOrderReceiptForm )
        {
            String filePath = null;
            String psAsHtml = null;

            try{
                psAsHtml = getOpenPOHtmlView ( host, purchaseOrderReceiptForm );
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

            if ( psAsHtml == null )
            {
                return filePath;
            }

            FileWriter fWriter = null;
            File psAttachment = null;

            try
            {
                String mailingTempDir = ConfigManager.getMailerTempDir ();
                File tempDir = new File ( mailingTempDir ).getCanonicalFile ();
                tempDir.mkdir ();
                String poAttachmentFileName = null;

                poAttachmentFileName = "Purchase_Order_Receipt_Ack_" + purchaseOrderReceiptForm.getPurchaseOrderNumber() + ".html";
                psAttachment = new File ( tempDir.getCanonicalPath (), poAttachmentFileName );

                psAttachment.deleteOnExit ();

                if ( ( psAttachment.exists () == true ) || ( psAttachment.createNewFile () == true ) )
                {
                    fWriter = new FileWriter ( psAttachment, false );

                    fWriter.write ( psAsHtml );

                    fWriter.close ();
                    fWriter = null;

                    filePath = psAttachment.getAbsolutePath ();
                }
            }
            catch ( Exception e )
            {
                System.out.println ( "Exception while creating Purchase Order Ack html file" );
                e.printStackTrace ();
            }
            finally
            {
                if ( fWriter != null )
                {
                    try
                    {
                        fWriter.close ();
                        fWriter = null;
                    }
                    catch ( IOException ignore )
                    {
                    }
                }
            }

            return filePath;
        }

        public String getOpenPOHtmlView( String host,  PurchaseOrderReceiptForm purchaseOrderReceiptForm ) throws ScalarException
        {
            StringBuffer buf = new StringBuffer();

            ArrayList poLineItems    = purchaseOrderReceiptForm.getReceivingLineItemList();
            String scalarLogo 			= ConfigManager.getScalarLogo();

            buf.append ("<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE><META http-equiv=Content-Type content='text/html; charset=windows-1252'>\n");

            buf.append ("<style type=\"text/css\">\n");
            buf.append ("#toc a{ font-family: Verdana;font-style : normal ;font-size : 9pt; font-weight :bold;}");
            buf.append ("#toc p{font-family: Verdana;font-style : normal ;font-size : 9pt; font-weight :bold;text-align :center;color :#FFFFFF}");
            buf.append ("#toc {border-style : solid;border-color :#000000 ;border-width :medium }");
            buf.append (".NArialW{ COLOR: #000000;font-family: arial;font-size: 18pt}");
            buf.append (".NArialL{ COLOR: #000000;font-family: verdana;font-size: 8pt;font-weight:bold}");
            buf.append (".NArialR{ COLOR: #000000; FONT-FAMILY: verdana; FONT-SIZE: 7pt; font-weight:bold}");
            buf.append (".NArialRS{ COLOR: #000000; FONT-FAMILY: verdana; FONT-SIZE: 7pt;}");
            buf.append ("</style></head>\n");

            buf.append ("<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight='0' marginwidth='0'><br>\n");
            buf.append ("<table width='95%' cellspacing='0' cellpadding='0' border=0 align=right>\n");
            buf.append ("<tr><td width='98%'>\n");

                buf.append ("<table border='0' width='98%'>\n");
                buf.append( "<tr>" );
                    buf.append( "<td colspan='5'>" );
                        buf.append( "<table width ='100%'>" );
                            buf.append( "<tr>" );
                                buf.append( "<td width='10%' align='center'><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif' height='5'></td>" );
                                buf.append( "<td width='20%' align='left' valign='top'><img src='http://" + host + "/"+ ConfigManager.getChipTracContext () +"/jsp/includes/images"+scalarLogo+" ' height='84' width='200' border=0></td> " );
                                buf.append( "<td width='40%'  align='center' class='NArialL'><font class='NArialW'>Purchase Order Receipt Acknowledgement</font>" );
                                buf.append( purchaseOrderReceiptForm.getClientAddrWithOutEmailObjFormatted() ).append("</td>");
                                buf.append( "<td width='20%' align='center'><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif' height='5'></td>" );
                                buf.append( "<td width='10%' align='center'><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif' height='5'></td>" );
                            buf.append( "<tr>" );
                        buf.append( "</table>" );
                    buf.append( "</td>" );
                buf.append( "<tr>" );

            buf.append ("<tr><td width='98%'> ");
            buf.append ("<table width='98%' cellspacing='0' cellpadding='0' border=0 >\n");
            buf.append ("<tr><td colspan=5><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif'' height=5></td></tr>\n");
            buf.append ("<tr><td colspan=5><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif'' height=5></td></tr>\n");
            buf.append ("<tr><td colspan=5><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif'' height=5></td></tr>\n");
            buf.append ("<tr>\n");
            buf.append ("<td colspan='5'>\n");
                buf.append ("<table width='98%' border=1 bordercolor='#000000' cellspacing='0' cellpadding='0' align='left'>\n");
                    buf.append ("<tr height=20>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Receipt&nbsp;Number</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>PO&nbsp;Number</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Receipt&nbsp;Date</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Vendor&nbsp;Name</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Invoice&nbsp;Number</td>\n");
                    buf.append ("</tr>\n");

                    buf.append ("<tr height=20>\n");
                    buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center>\n").append( purchaseOrderReceiptForm.getReceipt_Number() ).append("</td>\n");
                    buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center nowrap>\n").append( purchaseOrderReceiptForm.getPurchaseOrderNumber() ).append("&nbsp;</td>\n");
                    buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center nowrap>\n").append( purchaseOrderReceiptForm.getReceiptDate() ).append("&nbsp;</td>\n");
                    buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center wrap>\n").append( ( ( purchaseOrderReceiptForm.getVendorName() == null ) ? "" : purchaseOrderReceiptForm.getVendorName() ) ).append("&nbsp;</td>\n");
                    buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center wrap>\n").append( ( ( purchaseOrderReceiptForm.getInvoiceNumber() == null ) ? "" : purchaseOrderReceiptForm.getInvoiceNumber() ) ).append("&nbsp;</td>\n");
                    buf.append ("</tr>\n");
                buf.append ("</table>\n");
            buf.append ("</td>\n");
            buf.append ("</tr>\n");

            buf.append ("<tr><td width='98%'> ");
                buf.append ("<table width='98%' cellspacing='0' cellpadding='0' border=0 >\n");
                buf.append ("<tr><td><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif'' height=5></td></tr>\n");
                buf.append ("<tr><td><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif'' height=5></td></tr>\n");
                buf.append ("</table>\n");
            buf.append("</td></tr>\n");

            buf.append ("<tr><td width='98%'> ");
                buf.append ("<table width='98%' cellspacing='0' cellpadding='0' border=0 >\n");
                buf.append ("<tr><td colspan=5><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif'' height=5></td></tr>\n");
                buf.append ("<tr><td colspan=5><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif'' height=5></td></tr>\n");
                buf.append ("<tr><td colspan=5><img src='/chiptrac_cavium/jsp/includes/images/spacer.gif'' height=5></td></tr>\n");
                buf.append ("<tr>\n");
                buf.append ("<td colspan='5'>\n");
                    buf.append ("<table width='100%' border=1 bordercolor='#000000' cellspacing='0' cellpadding='0' align='center'>\n");
                    buf.append ("<tr height=20>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Line&nbsp;Item</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Process&nbsp;Name</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Part&nbsp;Number</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Description</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>package&nbsp;Type</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Req.&nbsp;Date</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Recv.&nbsp;Date</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Req.&nbsp;Qty</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Recv.&nbsp;Qty</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Lot.&nbsp;Info</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Unit&nbsp;Cost($)</td>\n");
                    buf.append ("<td class='NArialL' bgcolor='#DEE1E2' align=center>Ext.&nbsp;Cost($)</td>\n");
                    buf.append ("</tr>\n");

                if ( poLineItems != null )
                {
                    for ( int i = 0; i < poLineItems.size(); i++)
                    {
                        ReceivingLineItem poLineItem = ( ReceivingLineItem ) poLineItems.get( i );
                        buf.append ("<tr height=20>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center>\n").append(i+1).append("</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center nowrap>\n").append( poLineItem.getProcessName() ).append("&nbsp;</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center nowrap>\n").append( poLineItem.getPartNumber() ).append("&nbsp;</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center wrap>\n").append( poLineItem.getDescription() != null ? poLineItem.getDescription() : "").append("&nbsp;</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center>\n").append( poLineItem.getPackageType() == null ? "" : poLineItem.getPackageType() ).append("&nbsp;</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center>\n").append( poLineItem.getRequestedDate() != null ? poLineItem.getRequestedDate() : "" ).append("&nbsp;</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=center>\n").append( poLineItem.getReceivedDate() != null ? poLineItem.getReceivedDate() : "" ).append("&nbsp;</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=right>\n").append( poLineItem.getRequestedQuantity() ).append("&nbsp;</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=right>\n").append( poLineItem.getShippedQty() ).append("&nbsp;</td>\n");

                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=right>\n");

                        PurchaseOrderLineItemLotDataEntryList PurchaseOrderLineItemLotDataEntryList = poLineItem.getPurchaseOrderLineItemLotDataEntryList();
                        int lotListSize = 0;
                        if( PurchaseOrderLineItemLotDataEntryList != null )
                        {
                            lotListSize = PurchaseOrderLineItemLotDataEntryList.size();
                        }

                        for( int j = 0; j< lotListSize; j++  )
                        {
                            PurchaseOrderLineItemLotDataEntry purchaseOrderLineItemLotDataEntry = new PurchaseOrderLineItemLotDataEntry();
                            purchaseOrderLineItemLotDataEntry = ( PurchaseOrderLineItemLotDataEntry )PurchaseOrderLineItemLotDataEntryList.get( j );
                            buf.append("<table CLASS='NArialL'><tr>");
                                buf.append("<td ALIGN='CENTER' BGCOLOR='#FFFFEE'>").append( purchaseOrderLineItemLotDataEntry.getLotNumber() ).append("</td>") ;
                                buf.append("<td ALIGN='CENTER' BGCOLOR='#FFFFEE'>").append( purchaseOrderLineItemLotDataEntry.getQtyIn() ).append("</td>") ;
                                /*buf.append("<td ALIGN='CENTER' BGCOLOR='#FFFFEE'>").append( purchaseOrderLineItemLotDataEntry.getQtyOut() ).append("</td>") ;*/
                            buf.append("</tr></table>");
                        }
                        buf.append("&nbsp;</td>\n");

                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=right>&nbsp;\n").append( poLineItem.getUnitCost()).append("</td>\n");
                        buf.append ("<td bgcolor='#FFFFEE' class='NArialL' align=right>&nbsp;\n").append( poLineItem.getExtendedCostAsString() ).append("</td>\n");
                        buf.append ("</tr>\n");
                    }
                }
                buf.append ("</table>\n");
                buf.append ("</td>\n");
                buf.append ("</tr>\n");

                buf.append ("<tr>\n");
                buf.append ("<td colspan='5'>\n");
                    buf.append ("<table width='21%' border=1 align=right bordercolor='#000000'  cellspacing='0' cellpadding='0'>\n");
                    buf.append ("<tr><td bgcolor='#DEE1E2' class='NArialL' align=right >Sub Total:$</td><td bgcolor='#FFFFEE' class='NArialL'  align='right'>\n").append( purchaseOrderReceiptForm.getSub_totalAsString() ).append("</td></tr>\n");
                    buf.append ("<tr><td bgcolor='#DEE1E2' class='NArialL'  width='67%' align=right >Freight:$</td><td bgcolor='#FFFFEE'  class='NArialL' align='right'  width='33%'>\n").append( purchaseOrderReceiptForm.getFrieght() ).append("</td></tr>\n");
                    buf.append ("<tr><td bgcolor='#DEE1E2' class='NArialL' nowrap align=right >Trade Discount:$</td><td bgcolor='#FFFFEE'  class='NArialL' align='right'>\n").append( purchaseOrderReceiptForm.getTrade_Discount() ).append("</td></tr>\n");
                    buf.append ("<tr><td bgcolor='#DEE1E2' class='NArialL' align=right >Miscellaneous:$</td><td class='NArialL' bgcolor='#FFFFEE' align='right'>\n").append( purchaseOrderReceiptForm.getMiscellaneous() ).append("</td></tr>\n");
                    buf.append ("<tr><td bgcolor='#DEE1E2' class='NArialL' align=right >Tax:$</td><td  class='NArialL' bgcolor='#FFFFEE' align='right'>\n").append( purchaseOrderReceiptForm.getTaxAsString() ).append("</td></tr>\n");
                    buf.append ("<tr><td bgcolor='#DEE1E2' class='NArialL' align=right >Order Total:$</td><td  class='NArialL' bgcolor='#FFFFEE' align='right'>\n").append( purchaseOrderReceiptForm.getTotalAsString() ).append("</td></tr>\n");
                    buf.append ("</table>\n");
                buf.append ("</td>\n");
                buf.append ("</tr>\n");
                buf.append ("</table><br><br><br><br>\n");

            buf.append ("</td></tr>\n");
            buf.append ("</table>\n");

            buf.append ("<table width='60%' border='0'>\n");
            buf.append ("</table>\n");

            buf.append ("</form></html></BODY></HTML>\n");

            return buf.toString();
        }

        public static String getPurchaseOrderAsPDFFile(PurchaseOrderReceiptForm purchaseOrderReceiptForm )
        {

            String fileXMLPath 		= null;
            String filePDFPath 		= null;
            String fileXSLTPath 	= null;
            FileWriter fWriter 		= null;
            File psPDFAttachment 	= null;
            File psXML 				= null;
            String psAsXML 			= formatAsXML( purchaseOrderReceiptForm );
            if( psAsXML == null )
            {
                return fileXMLPath;
            }

            try
            {
                String mailingTempDir 		    = ConfigManager.getMailerTempDir();
                File tempDir 				    = new File ( mailingTempDir ).getCanonicalFile();
                String poAttachmentFileName     = purchaseOrderReceiptForm.getPurchaseOrderNumber();
                String xmlFileName 			    = "Purchase_Order_Receipt" + poAttachmentFileName + ".xml";
                String  xsltFileName		    = ConfigManager.getPurchaseOrderReceiptEntryXml2PdfXslFile();
                String poAttachmentPDFFileName  = "Purchase_Order_Receipt" + poAttachmentFileName + ".pdf";

                tempDir.mkdir();

                if( ( poAttachmentFileName != null ) && ( poAttachmentFileName.startsWith( "PO-" ) ) )
                {
                    poAttachmentFileName = poAttachmentFileName.substring( 3 );
                }

                psXML = new File( tempDir.getCanonicalPath(), xmlFileName );
                psXML.deleteOnExit();

                psPDFAttachment = new File( tempDir.getCanonicalPath(), poAttachmentPDFFileName );
                psPDFAttachment.deleteOnExit();

                if( ( psXML.exists() == true ) || ( psXML.createNewFile() == true ) )
                {
                    fWriter = new FileWriter ( psXML, false);
                    fWriter.write ( psAsXML );
                    fWriter.close();
                    fWriter = null;

                    fileXMLPath = psXML .getCanonicalPath() .toLowerCase();
                    filePDFPath = psPDFAttachment .getCanonicalPath() .toLowerCase();
                    boolean success = PDFGenerator.convertXML2PDF( fileXMLPath, xsltFileName, filePDFPath );
                }
            }
            catch( Exception e )
            {
                System.out.println( "Exception while creating purchase order PDF file");
                e.printStackTrace();
            }
            finally
            {
                if( fWriter != null )
                {
                    try
                    {
                        fWriter.close();
                        fWriter = null;
                    }
                    catch( IOException ignore ){}
                }
            }

            return filePDFPath;
        }

        public static String formatAsXML ( PurchaseOrderReceiptForm purchaseOrderReceiptForm )
        {

            StringBuffer buf 			= new StringBuffer ( 2098 );

            ArrayList poLineItems = purchaseOrderReceiptForm.getReceivingLineItemList();

            String imagesDirLocation 	= ConfigManager.getChipTracImagesDir();
            String scalarLogo 			= ConfigManager.getScalarLogo();

            buf.append ( "<?xml version='1.0' encoding='UTF-8'?>" + "\n" );
            buf.append ( "<purchaseOrder> \n" );

            buf.append ( "<images>\n" );
            buf.append ( "<logo>"+imagesDirLocation + scalarLogo +"</logo> \n" );
            buf.append ( "</images>\n" );

            buf.append ( "<selfAddress> \n" );

            ClientInfo c_address  = new ClientInfo();
            Address address       = new Address();
            try
            {
                c_address  = purchaseOrderReceiptForm.getClientInfo();
                address    = c_address.getAddress();

            }
            catch( Exception e)
            {
                e.printStackTrace();
            }
            buf.append ( "<name><![CDATA[" ) .append( ( ( c_address.getClientName() == null ) ? "" : c_address.getClientName() ) ) .append( "]]></name> \n" );
            buf.append ( "<address1><![CDATA[" );
            buf.append ( ( ( address.getAddress1() == null ) ? "" : address.getAddress1().trim() ) );
            buf.append ( "]]></address1> \n" );

            buf.append ( "<address2><![CDATA[" );
            buf.append ( ( ( address.getAddress2() == null ) ? "" : address.getAddress2().trim() ) );
            buf.append ( "]]></address2> \n" );

            buf.append ( "<address3><![CDATA[" );
            buf.append ( ( ( address.getAddress3() == null ) ? "" : address.getAddress3().trim() ) );
            buf.append ( "]]></address3> \n" );

            buf.append ( "<address4><![CDATA[" );
            buf.append ( ( ( address.getAddress4() == null ) ? "" : address.getAddress4().trim() ) );
            buf.append ( "]]></address4> \n" );

            StringBuffer cityStateZip = new StringBuffer ( "" );

            if ( !address.getCity ().equals ( "" ) ) cityStateZip.append ( address.getCity () + ", " );
            if ( !address.getState ().equals ( "" ) ) cityStateZip.append ( address.getState () + " - " );
            if ( !address.getZipCode ().equals ( "" ) ) cityStateZip.append ( address.getZipCode () + ", " );
            cityStateZip.append ( address.getCountry () );

            buf.append ( "<cityStateZip><![CDATA[" + cityStateZip + "]]></cityStateZip>" + "\n" );

            StringBuffer phFax = new StringBuffer ();
            if ( !address.getPhoneNumber ().equals ( "" ) ) phFax.append ( "Ph:" + address.getPhoneNumber () + ", " );
            if ( !address.getFaxNumber ().equals ( "" ) ) phFax.append ( "Fax:" + address.getFaxNumber () );

            buf.append ( "<phoneFax><![CDATA[" + phFax + "]]></phoneFax>" + "\n" );

            buf.append ( "</selfAddress> \n" );

            buf.append ( "<purchaseOrderDetails> \n" );
            buf.append ( "<receiptNumber><![CDATA[" ) .append( purchaseOrderReceiptForm.getReceipt_Number() ) .append( "]]></receiptNumber> \n" );
            buf.append ( "<poNumber><![CDATA[" ) .append( ( ( purchaseOrderReceiptForm.getPurchaseOrderNumber() == null ) ? "" : purchaseOrderReceiptForm.getPurchaseOrderNumber() ) ) .append( "]]></poNumber> \n" );
            buf.append ( "<date><![CDATA[" ) .append( purchaseOrderReceiptForm.getReceiptDate() ) .append( "]]></date> \n" );
            buf.append ( "<vendorName><![CDATA[" ) .append( ( ( purchaseOrderReceiptForm.getVendorName() == null ) ? "" : purchaseOrderReceiptForm.getVendorName() ) ) .append( "]]></vendorName> \n" );
            buf.append ( "<invoiceNumber><![CDATA[" ) .append( ( ( purchaseOrderReceiptForm.getInvoiceNumber() == null ) ? "" : purchaseOrderReceiptForm.getInvoiceNumber() ) ) .append( "]]></invoiceNumber> \n" );
            buf.append ( "</purchaseOrderDetails> \n" );

            /*buf.append ( "<billingAddress> \n" );
            buf.append ( getXMLFormattedAddress( "", address.getContactPerson(), address.getAddress1(), address.getAddress2(), address.getAddress3(), address.getAddress4(), address.getCity(), address.getState(), address.getZipCode(), address.getCountry(), address.getPhoneNumber(), address.getCellNumber(), address.getFaxNumber(), address.getEmail() ) );
            buf.append ( "</billingAddress> \n" );

            buf.append ( "<shipToAddress> \n" );
            Address s_address = new Address();
            try
            {
                s_address  = purchaseOrderReceiptForm.getShippingAddress();
                System.out.println("s_address = " + s_address);
            }
            catch( Exception e)
            {
                e.printStackTrace();
            }
            buf.append ( getXMLFormattedAddress( s_address.getContactPerson(), s_address.getContactPerson(), s_address.getAddress1(), s_address.getAddress2(), s_address.getAddress3(), s_address.getAddress4(), s_address.getCity(), s_address.getState(), s_address.getZipCode(), s_address.getCountry(), s_address.getPhoneNumber(), s_address.getCellNumber(), s_address.getFaxNumber(), s_address.getEmail() ) );
            buf.append ( "</shipToAddress> \n" );

            buf.append ( "<Comments><![CDATA[" );
            buf.append ( ( ( purchaseOrderForm.getComments() == null ) ? "" : purchaseOrderForm.getComments().trim() ) );
            buf.append ( "]]></Comments> \n" );*/

            buf.append ( "<lineItems> \n" );
            if ( poLineItems != null )
            {
                for ( int i = 0; i < poLineItems.size(); i++)
                {
                    ReceivingLineItem poLineItem = ( ReceivingLineItem ) poLineItems.get( i );

                    buf.append ( "<lineItem> \n" );
                    buf.append ( "<poLineItem><![CDATA[" ) .append ( i+1 ) .append ( "]]></poLineItem> \n" );
                    buf.append ( "<ProcessName><![CDATA[" ) .append ( poLineItem.getProcessName() ) . append( "]]></ProcessName>\n" );
                    buf.append ( "<PartNumber><![CDATA[" ) .append ( poLineItem.getPartNumber() ) . append( "]]></PartNumber>\n" );
                    buf.append ( "<description><![CDATA[" );
                    buf.append ( ( ( ( poLineItem.getDescription() == null ) || ( poLineItem.getDescription().trim().length() == 0 ) ) ? "" : poLineItem.getDescription().trim() ) );
                    buf.append ( "]]></description>\n" );
                    buf.append ( "<PakType><![CDATA[" ) .append ( poLineItem.getPackageType() == null ? "" : poLineItem.getPackageType() ) . append( "]]></PakType>\n" );
                    buf.append ( "<requestDate><![CDATA[" ) .append ( poLineItem.getRequestedDate() != null ? poLineItem.getRequestedDate() : "" ) .append ( "]]></requestDate>\n" );
                    buf.append ( "<recvDate><![CDATA[" ) .append ( poLineItem.getReceivedDate() != null ? poLineItem.getReceivedDate() : "" ) .append ( "]]></recvDate>\n" );
                    buf.append ( "<reqQty><![CDATA[" ) .append( poLineItem.getRequestedQuantity()  ).append ( "]]></reqQty>\n" );
                    buf.append ( "<recvQty><![CDATA[" ) .append( poLineItem.getShippedQty() ).append ( "]]></recvQty>\n" );

                    buf.append ( "<lotNumbers> \n" );
                    PurchaseOrderLineItemLotDataEntryList PurchaseOrderLineItemLotDataEntryList = poLineItem.getPurchaseOrderLineItemLotDataEntryList();
                    int lotListSize = 0;
                    if( PurchaseOrderLineItemLotDataEntryList != null )
                    {
                        lotListSize = PurchaseOrderLineItemLotDataEntryList.size();
                    }
                    for( int j = 0; j < lotListSize; j++  )
                    {
                        PurchaseOrderLineItemLotDataEntry purchaseOrderLineItemLotDataEntry = new PurchaseOrderLineItemLotDataEntry();
                        purchaseOrderLineItemLotDataEntry = ( PurchaseOrderLineItemLotDataEntry )PurchaseOrderLineItemLotDataEntryList.get( j );
                        buf.append ( "<lotInfo> \n" );
                            buf.append( "<lotNumber><![CDATA[" ).append( purchaseOrderLineItemLotDataEntry.getLotNumber() ).append( "]]></lotNumber>\n" ) ;
                            buf.append( "<qtyIn><![CDATA[" ).append( purchaseOrderLineItemLotDataEntry.getQtyIn() ).append( "]]></qtyIn>\n" ) ;
                            buf.append( "<qtyOut><![CDATA[" ).append( purchaseOrderLineItemLotDataEntry.getQtyOut() ).append( "]]></qtyOut>\n" ) ;
                        buf.append ( "</lotInfo> \n" );
                    }
                    buf.append ( "</lotNumbers> \n" );

                    buf.append ( "<unitPrice><![CDATA[" + poLineItem.getUnitCost() + "]]></unitPrice>" + "\n" );
                    buf.append ( "<extendedPrice><![CDATA[" + poLineItem.getExtendedCostAsString() + "]]></extendedPrice>" + "\n" );
                    //buf.append ( "<status><![CDATA[" + poLineItem.getStatus() + "]]></status>" + "\n" );
                    buf.append ( "</lineItem>" + "\n" );
                }
            }
            buf.append ( "</lineItems> \n" );

            buf.append ( "<total><![CDATA[" + purchaseOrderReceiptForm.getSub_totalAsString() + "]]></total>" + "\n" );
            buf.append ( "<tradeDiscount><![CDATA[" + purchaseOrderReceiptForm.getTrade_Discount() + "]]></tradeDiscount>" + "\n" );
            buf.append ( "<freight><![CDATA[" + purchaseOrderReceiptForm.getFrieght() + "]]></freight>" + "\n" );
            buf.append ( "<misc><![CDATA[" + purchaseOrderReceiptForm.getMiscellaneous() + "]]></misc>" + "\n" );
            buf.append ( "<tax><![CDATA[" + purchaseOrderReceiptForm.getTaxAsString() + "]]></tax>" + "\n" );
            buf.append ( "<orderTotal><![CDATA[" + purchaseOrderReceiptForm.getTotalAsString() + "]]></orderTotal>" + "\n" );

            buf.append ( "</purchaseOrder> \n" );
            //System.out.println("\n\n PDF--XML \n" + buf.toString() + "\n");
            return buf.toString();
        }

        public static String getFormatedState( String state, String zipCode, String country )
        {
            String addr = "";
            if (   state != null  &&   state.trim().length() != 0 )
                addr =   state;
            if ( zipCode != null &&  zipCode.trim().length() != 0 )
            {
                if ( addr.trim().length() !=0 )
                    addr = addr + "&nbsp;-&nbsp;" + zipCode;
                else
                    addr = addr + zipCode;
            }
            if (   country != null  &&  country.trim().length() != 0  )
            {
                if ( addr.trim().length() != 0 )
                    addr = addr + ",&nbsp;" + country;
                else
                    addr = addr + country;
            }
            return addr.replaceAll("&nbsp;"," ");
        }

        public static String getFormattedAddress (String name, String contactName, String address1, String address2, String address3, String address4, String city, String state, String zipCode, String country, String phoneNumber, String cellNumber, String faxNumber, String emailId )
        {
            StringBuffer buffStr = new StringBuffer();
            String formatedAddresses =  null;

            if ( name != null  )
            {
                if ( ( contactName != null ) && ( contactName.trim().length() > 0 ) )
                {
                    if ( ! name.equalsIgnoreCase( contactName ) )
                    {
                        buffStr.append( ( name.trim().length() > 0 ) ? name + "<BR>" : "" );
                        buffStr.append( ( ( contactName == null ) || ( contactName.trim().length() == 0 ) ) ? "" : contactName );
                    }
                    else
                    {
                        buffStr.append( ( name.trim().length() > 0 ) ? name  : "" );
                    }
                }
                else
                {
                    buffStr.append( ( name.trim().length() > 0 ) ? name  : "" );
                }
            }
            else
            {
                buffStr.append( ( ( contactName == null ) || ( contactName.trim().length() == 0 ) ) ? "" : contactName );
            }
            buffStr.append ( ( ( address1   == null ) || (  address1.trim().length()    == 0 ) ) ? "" : "<BR>"  +  address1   );
            buffStr.append ( ( ( address2   == null ) || (  address2.trim().length()    == 0 ) ) ? "" : "<BR>"  +  address2   );
            buffStr.append ( ( ( address3   == null ) || (  address3.trim().length()    == 0 ) ) ? "" : "<BR>"  +  address3   );
            buffStr.append ( ( ( address4   == null ) || (  address4.trim().length()    == 0 ) ) ? "" : "<BR>"  +  address4   );
            buffStr.append ( ( ( city       == null ) || (  city.trim().length()        == 0 ) ) ? "" : "<BR>"  +  city       );

            String formatedState = getFormatedState( state, zipCode, country );
            if ( formatedState.trim().length() > 0 )
            {
                 buffStr.append ( "<BR>" + formatedState );
            }

            buffStr.append ( ( ( phoneNumber    != null ) && ( phoneNumber.trim().length()  > 0 ) ) ?  "<BR>Tel: "      + phoneNumber   : "" );
            buffStr.append ( ( ( cellNumber     != null ) && ( cellNumber.trim().length()   > 0 ) ) ?  "<BR>Cell No: "  + cellNumber    : "");
            buffStr.append ( ( ( faxNumber      != null ) && ( faxNumber.trim().length()    > 0 ) ) ?  "<BR>Fax: "      + faxNumber     : "" );
            buffStr.append ( ( ( emailId        != null ) && ( emailId.trim().length()      > 0 ) ) ?  "<BR>Email: "    + emailId       : "" );

            formatedAddresses = buffStr.toString();
            formatedAddresses = formatedAddresses.replaceAll("<br><br>","<br>");
            formatedAddresses = formatedAddresses.replaceAll("<br><br><br>","<br>");
            if( formatedAddresses.length() > 4 && formatedAddresses.substring(0,4).equalsIgnoreCase("<br>") )
            {
                try{
                    formatedAddresses = formatedAddresses.substring( 4 , formatedAddresses.length() );
                }catch(Exception e){
                    System.out.println("-----------ERROR = " + e);
                }
            }
            return  formatedAddresses ;
        }

        public static String getXMLFormattedAddress( String name, String contactName, String address1, String address2, String address3, String address4, String city, String state, String zipCode, String country, String phoneNumber, String cellNumber, String faxNumber, String emailId  )
        {

            StringBuffer formatAddress = new StringBuffer();

            formatAddress.append ( "<name><![CDATA[" );
            formatAddress.append ( ( ( name == null ) || ( ( name.trim().length() == 0 ) ) ) ? "" : name );
            formatAddress.append ( "]]></name> \n" );

            if( ( name != null ) && ( name.equalsIgnoreCase( contactName ) ) )
            {
                formatAddress.append ( "<contactname><![CDATA[ ]]></contactname> \n" );
            }
            else
            {
                formatAddress.append ( "<contactname><![CDATA[" );
                formatAddress.append ( ( ( contactName == null ) || ( ( contactName.trim().length() == 0 ) ) ) ? "" : contactName );
                formatAddress.append ( "]]></contactname> \n" );
            }

            formatAddress.append ( "<address1><![CDATA[" );
            formatAddress.append ( ( ( address1 == null ) || ( ( address1.trim().length() == 0 ) ) ) ? "" : address1 );
            formatAddress.append ( "]]></address1> \n" );

            formatAddress.append ( "<address2><![CDATA[" );
            formatAddress.append ( ( ( address2 == null ) || ( ( address2.trim().length() == 0 ) ) ) ? "" : address2 );
            formatAddress.append ( "]]></address2> \n" );

            formatAddress.append ( "<address3><![CDATA[" );
            formatAddress.append ( ( ( address3 == null ) || ( ( address3.trim().length() == 0 ) ) ) ? "" : address3 );
            formatAddress.append ( "]]></address3> \n" );

            formatAddress.append ( "<address4><![CDATA[" );
            formatAddress.append ( ( ( address4 == null ) || ( ( address4.trim().length() == 0 ) ) ) ? "" : address4 );
            formatAddress.append ( "]]></address4> \n" );

            formatAddress.append ( "<city><![CDATA[" );
            formatAddress.append ( ( ( city == null ) || ( city.trim().length()==0 ) ) ? "" : city );
            formatAddress.append ( "]]></city> \n" );

            String formatedState = "";
            formatedState = getFormatedState( state, zipCode, country );
            if ( formatedState.trim().length() > 0 )
               formatAddress.append( "<state><![CDATA["+formatedState+"]]></state> \n" );

            formatAddress.append ( "<phone><![CDATA[" );
            formatAddress.append ( ( ( phoneNumber != null ) && ( phoneNumber.trim().length() > 0 ) ) ?  "Tel: "+ phoneNumber +"" : "" );
            formatAddress.append ( "]]></phone> \n" );

            formatAddress.append ( "<cell><![CDATA[" );
            formatAddress.append ( ( ( cellNumber != null ) && ( cellNumber.trim().length() > 0 ) ) ?  "Cell No: "+ cellNumber +"" : "" );
            formatAddress.append ( "]]></cell> \n" );

            formatAddress.append ( "<fax><![CDATA[" );
            formatAddress.append ( ( ( faxNumber != null ) && ( faxNumber.trim().length() > 0 ) ) ? "Fax: "+ faxNumber : "" );
            formatAddress.append ( "]]></fax> \n" );

            formatAddress.append ( "<email><![CDATA[" );
            formatAddress.append ( ( ( emailId != null ) && ( emailId.trim().length() > 0 ) ) ? "Email: "+ emailId : "" );
            formatAddress.append ( "]]></email> \n" );

            return formatAddress.toString() ;
        }


    public PurchaseOrderLineItemLotDataEntryList getOpenPOLotList() {
        return openPOLotList;
    }

    public void setOpenPOLotList(PurchaseOrderLineItemLotDataEntryList openPOLotList) {
        this.openPOLotList = openPOLotList;
    }

    public String getInvoiceNumber() {
        return invoiceNumber;
    }

    public void setInvoiceNumber(String invoiceNumber) {
        this.invoiceNumber = invoiceNumber;
    }

    public double getPoMaxAmt() {
        return poMaxAmt;
    }

    public void setPoMaxAmt(double poMaxAmt) {
        this.poMaxAmt = poMaxAmt;
    }
    public String getPoMaxAmtFormatted() {
        return StringUtils.formatAmount( poMaxAmt );
    }

    public double getPrevReceiptsTotal() {
        return prevReceiptsTotal;
    }

    public void setPrevReceiptsTotal(double prevReceiptsTotal) {
        this.prevReceiptsTotal = prevReceiptsTotal;
    }
    public double getRemainingPOAmount()
    {
        return poMaxAmt-prevReceiptsTotal;
    }
    public String getRemainingPOAmountFormatted() 
    {
        return StringUtils.formatAmount( getRemainingPOAmount() );
    }
}
